package com.cms.jy.draft.util;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

import com.cms.jy.draft.entity.DraftSettings;

/**
 * 草稿设置写入工具类
 * 处理 draft_settings 文件（INI格式）
 */
public class DraftSettingsWriter {
    
    /**
     * 写入草稿设置
     * @param settings DraftSettings 对象
     * @param filePath 文件路径
     * @throws IOException IO异常
     */
    public static void writeDraftSettings(DraftSettings settings, String filePath) throws IOException {
        // 使用OutputStreamWriter确保UTF-8编码
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), StandardCharsets.UTF_8))) {
            // Write section header
            writer.write("[General]");
            writer.newLine();
            
            // Write key-value pairs
            writer.write("draft_create_time=" + settings.getDraft_create_time());
            writer.newLine();
            
            writer.write("draft_last_edit_time=" + settings.getDraft_last_edit_time());
            writer.newLine();
            
            writer.write("real_edit_seconds=" + settings.getReal_edit_seconds());
            writer.newLine();
            
            writer.write("real_edit_keys=" + settings.getReal_edit_keys());
            writer.newLine();
            
            writer.write("cloud_last_modify_platform=" + settings.getCloud_last_modify_platform());
            writer.newLine();
        }
    }
}